module.exports = {

  formatSeconds: function (a) {
    if (a === '--') return '--'
    a = a + ''
    if (a.charAt(a.length - 1) === 's') {
      a = a.substr(0, a.length - 1)
    }
    a = review(a)
    a = Number(a)
    if (isNaN(a)) {
      return ''
    }
    var flag = a < 0
    a = Math.abs(a)
    var hh = parseInt(a / 3600);
    if (hh < 10) hh = '0' + hh;
    var mm = parseInt((a - hh * 3600) / 60);
    if (mm < 10) mm = '0' + mm;
    var ss = Math.round((a - hh * 3600) % 60);
    if (ss < 10) ss = '0' + ss;
    var length = hh + ':' + mm + ':' + ss;
    if (flag) length = '-' + length
    return length
  },
  formatHSM: (time) => {
    if (time === '--') return '--'
    time = '' + time
    if (time.charAt(time.length - 1) === 's') {
      time = time.substr(0, time.length - 1)
    }
    time = review(time)
    if (!time.includes(':')) {
      if (isNaN(time)) return 0
      return time + 's'
    }
    // var hour = time.split(':')[0];
    // var min = time.split(':')[1];
    // var sec = time.split(':')[2];
    // return Number(hour * 3600) + Number(min * 60) + Number(sec) + 's'
  },
  review
}
function review (a) {
  a = a + ''
  if (a.charAt(a.length - 1) === 's') {
    a = a.substr(0, a.length - 1)
    return a
  }
  if (a.includes(':')) {
    a = format(a) + ''
  } else if (!isNaN(Number(a))) {
    a = Number(a) + ''
  } else {
    a = '0'
  }
  return a
}
function format (time) {
  var flag = time.charAt(0) === '-'
  if (flag) {
    time = time.substr(1)
  }
  var hour = time.split(':')[0];
  var min = time.split(':')[1];
  var sec = time.split(':')[2];
  const number = Number(hour * 3600) + Number(min * 60) + Number(sec)
  if (flag) return -number
  return number
}
